package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.ScoreInfo;
import com.ruoyi.system.mapper.ScoreInfoDao;
import com.ruoyi.system.service.ScoreInfoService;
import org.springframework.stereotype.Service;

/**
 * Auto created by codeAppend plugin
 */
@Service
public class ScoreInfoServiceImpl extends ServiceImpl<ScoreInfoDao, ScoreInfo> implements ScoreInfoService {
    @Override
    public void insertScoreInfo(ScoreInfo scoreInfo) {
        ScoreInfo si = new ScoreInfo();
        si.setUserId(scoreInfo.getUserId());
        si.setScenicId(scoreInfo.getScenicId());
        si.setScore(scoreInfo.getScore());
        baseMapper.insert(si);
    }

    @Override
    public ScoreInfo getScoreInfoById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public boolean updateScoreInfo(ScoreInfo scoreInfo) {
        LambdaQueryWrapper<ScoreInfo> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ScoreInfo::getId, scoreInfo.getId());
        ScoreInfo si = baseMapper.selectOne(lqw);
        if (si == null){
            throw new RuntimeException("ScoreInfo not found");
        }
        si.setUserId(scoreInfo.getUserId());
        si.setScenicId(scoreInfo.getScenicId());
        si.setScore(scoreInfo.getScore());
        return baseMapper.updateById(si) > 0;
    }

    @Override
    public boolean deleteScoreInfoById(Long id) {
        return baseMapper.deleteById(id) > 0;
    }

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

}
